<!DOCTYPE html >
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>添加新用户页面</title>
    <div th:include="common :: headcommon"></div>
    <script type="text/javascript" src="/xadmin/js/xadmin.js"></script>
    <script th:src="@{/js/index/register.js}" type="text/javascript"></script>

</head>
<body>

<div  style="padding-top: 10px;width: 700px;">

        <form class="layui-form "  >
            <input type="hidden" name="uid" th:value="${userInfo?.uid}" value="">
            <div class="layui-form-item">
                <label class="layui-form-label">用户账号</label>
                <div class="layui-input-inline">
                    <input type="text" name="uname" required lay-verify="uname" placeholder="请输入用户账号" disabled
                           autocomplete="off" class="layui-input"  th:value="${userInfo?.uname}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码框</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" required lay-verify="password" placeholder="请输入密码"
                           autocomplete="off" class="layui-input" id="password" th:value="${userInfo?.password}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="男" title="男" th:field="*{userInfo.sex}" >
                    <input type="radio" name="sex" value="女" title="女" th:field="*{userInfo.sex}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机号</label>
                <div class="layui-input-block" style="width: 190px">
                    <input type="tel" name="telephone" required lay-verify="tel" placeholder="请输入用户手机号"
                           autocomplete="off" class="layui-input" th:value="${userInfo?.telephone}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block" style="width: 190px" >
                    <input type="email" name="email" required lay-verify="required" placeholder="请输入用户邮箱"
                           autocomplete="off" class="layui-input" th:value="${userInfo?.email}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">是否激活账号</label>
                <div class="layui-input-block">
                    <input type="radio" name="active" value="1" title="是"  th:field="*{userInfo.active}">
                    <input type="radio" name="active" value="0" title="否" th:field="*{userInfo.active}">
                </div>
            </div>

            <div class="layui-form-item" th:if="${userInfo.lid} eq 2">
                <label class="layui-form-label">是否为管理员</label>
                <div class="layui-input-block">
                    <input type="radio" name="adRole" value="1" title="是"  th:field="*{userInfo.adRole}">
                    <input type="radio" name="adRole" value="0" title="否" th:field="*{userInfo.adRole}">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">用户等级:</label>
                <div class="layui-input-block">
                    <select name="lid">
                        <!--     selected        不选择为0默认查询所有等级-->
                        <option  value="" >请选择用户等级</option>
                        <option th:field="*{userInfo.lid}" value="1" >1</option>
                        <option th:field="*{userInfo.lid}"  th:if="${session.back_user.lid} eq '3'" value="2" >2</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item" style="padding-top: 10px;">
                <div class="layui-input-block">
                    <button class="layui-btn" type="button" lay-submit lay-filter="editUser">修改</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
</div>
<script>
    layui.use(['form','jquery','layer'],function (){
        var form = layui.form,
            $ = layui.jquery;

        form.on('submit(editUser)',function (data){
           var param=data.field;
           console.log(param);
            $.ajax({
                url:'/back/user/editResult',
                type:'post',
                // async:false,
                data:JSON.stringify(param),
                contentType: "application/json; charset=utf-8",
                dataType:"json",
                success:function (data){
                    // console.log("接收的数据为"+data);
                    //编辑失败
                    if (data.status==400 || data.status==401){
                        layer.msg(data.msg,{icon:0,time :3000});
                    }
                    //编辑成功
                    if (data.status==200){
                        layer.alert(data.msg,function (){
                            // window.location.href='/back/user/manage';
                            x_admin_close();

                        })

                        // layer.msg(data.msg,{icon:1,time: 3000});
                         // setTimeout(function () {window.location.href='/back/user/manage';},2000);
                        //window.location.href='/index';
                    }
                }

            });

        });
    })
</script>
</body>
</html>